package com.ct.controller.coupon;


import com.ct.application.commons.vo.StatusRequest;
import com.ct.application.coupon.model.po.CouponAddPO;
import com.ct.application.coupon.model.po.CouponQueryPO;
import com.ct.application.coupon.model.po.CouponUpdatePO;
import com.ct.application.coupon.model.vo.CouponVO;
import com.ct.application.coupon.service.CouponService;
import com.ct.commons.BaseController;
import com.ct.commons.annotation.ApiLog;
import com.ct.commons.annotation.HasAdmin;
import com.ct.commons.annotation.PermissionApi;
import com.ct.commons.aspect.limiter.AccessIpLimiter;
import com.ct.repository.commons.PageUtils;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * 管理后台-优惠券模块
 *
 * @author system
 * @since 2024-03-05
 */
@RestController
@PermissionApi(title = "优惠券模块",path="/api/v1/coupon",code = "B1000",sorted = 4)
public class CouponController extends BaseController {

    @Resource
    private CouponService couponService;


    /**
     * 获取优惠券列表数据
     */
    @PostMapping("/coupon/getCouponList")
    @PermissionApi(title = "优惠券列表",path="/api/v1/coupon/getCouponList",code = "B1001",sorted = 1)
    public PageUtils<CouponVO> getCouponList(@Valid @RequestBody CouponQueryPO queryPO) {
        return couponService.getCouponList(queryPO);
    }


    /**
     * 根据id查询优惠券
     */
    @PostMapping("/coupon/get/{id}")
    @PermissionApi(title = "查询优惠券明细",path="/api/v1/coupon/get/{id}",code = "B1002",sorted = 2)
    public CouponVO getCouponById(@PathVariable("id") Long id) {
        return couponService.getCouponById(id);
    }


    /**
     * 新增优惠券
     */
    @PostMapping("/coupon/add")
    @HasAdmin
    @AccessIpLimiter
    @ApiLog("新增优惠券")
    @PermissionApi(title = "新增优惠券",path="/api/v1/coupon/add",code = "B1003",sorted = 3)
    public Boolean add(@Valid @RequestBody CouponAddPO po) {
        return couponService.add(po);
    }


    /**
     * 修改优惠券
     */
    @PostMapping("/coupon/update")
    @HasAdmin
    @AccessIpLimiter
    @ApiLog("修改优惠券")
    @PermissionApi(title = "修改优惠券",path="/api/v1/coupon/update",code = "B1004",sorted = 4)
    public Boolean update(@RequestBody CouponUpdatePO po) {
        return couponService.update(po);
    }


    /**
     * 删除优惠券
     */
    @PostMapping("/coupon/delete/{id}")
    @HasAdmin
    @AccessIpLimiter
    @ApiLog("删除优惠券")
    @PermissionApi(title = "删除优惠券",path="/api/v1/coupon/delete/{id}",code = "B1005",sorted = 5)
    public Boolean delete(@PathVariable("id") Long id) {
        return couponService.delete(id);
    }


    @PostMapping("/coupon/update/status")
    @HasAdmin
    @AccessIpLimiter
    @ApiLog("修改状态")
    @PermissionApi(title = "优惠券修改状态",path="/api/v1/coupon/update/status",code = "B1006",sorted = 6)
    public Boolean updateStatus(@RequestBody StatusRequest statusRequest) {
        return couponService.updateStatus(statusRequest);
    }
}

